﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.classesBasicas.jogo;
using Biblioteca.fachada;

namespace Desktop.views.cruds.crudsJogo.crudCampo
{
    public partial class MenuCampo : Form
    {
        private TelaInicial telaInicial;
        private Campo campo = new Campo();
        private Fachada fachada = new Fachada();
        private List<Campo> listaCampos;

        
        public MenuCampo(TelaInicial telaInicial)
        {
            this.telaInicial = telaInicial;
            telaInicial.Hide();

            InitializeComponent();
        }

        private void buttonCadastrar_Click(object sender, EventArgs e)
        {
            CadastroCampo cadastroCampo = new CadastroCampo(this);
            cadastroCampo.ShowDialog();
        }

        private void buttonSair_Click(object sender, EventArgs e)
        {
            telaInicial.Show();
            this.Dispose();
        }

        private void MenuCampo_FormClosed(object sender, FormClosedEventArgs e)
        {
            telaInicial.Show();
            this.Dispose();
        }

        private void MenuCampo_Load(object sender, EventArgs e)
        {
            this.carregarGridViewCampo();
        }


        private void dataGridViewCampo_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                DataGridViewRow row = this.dataGridViewCampo.Rows[e.RowIndex];

                campo.Id = row.Cells[0].Value.ToString();
                campo.Tipo = row.Cells[1].Value.ToString();
                campo.Tamanho = row.Cells[2].Value.ToString();

                AlterarRemoverCampo alterar = new AlterarRemoverCampo(this, campo);
                alterar.ShowDialog();
            }
        }


        public void carregarGridViewCampo()
        {
            listaCampos = fachada.listarCampo();

            DataGridViewCellStyle columnHeaderStyle =
            new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            columnHeaderStyle.Font =
                new Font("Verdana", 10, FontStyle.Bold);
            this.dataGridViewCampo.ColumnHeadersDefaultCellStyle =
                columnHeaderStyle;

            dataGridViewCampo.DataSource = listaCampos;

            this.dataGridViewCampo.Columns[0].HeaderText = "ID";
            this.dataGridViewCampo.Columns[1].HeaderText = "TIPO";
            this.dataGridViewCampo.Columns[2].HeaderText = "TAMANHO";            
        }

    }
}
